package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;

public class Name {
   zpm a = null;
   zaoe b = new zaoe();
   private String d;
   private String e;
   private String f;
   private String g;
   private String h;
   private byte i;
   private byte j;
   private int k;
   private WorksheetCollection l;
   String c;
   private static final com.aspose.cells.b.c.a.za m = new com.aspose.cells.b.c.a.za(new String[]{"CONSOLIDATE_AREA", "AUTO_OPEN", "AUTO_CLOSE", "EXTRACT", "DATABASE", "CRITERIA", "PRINT_AREA", "PRINT_TITLES", "RECORDER", "DATA_FORM", "AUTO_ACTIVATE", "AUTO_DEACTIVATE", "SHEET_TITLE", "_FILTERDATABASE", "OFFSET", "INDIRECT", ":"});

   int a() {
      return this.b.d;
   }

   void a(int var1) {
      this.b.d = var1;
   }

   byte[] b() {
      return this.b.f;
   }

   void a(byte[] var1) {
      this.b.f = var1;
   }

   String c() {
      return this.d;
   }

   void a(String var1) {
      this.d = var1;
   }

   String d() {
      return this.e;
   }

   void b(String var1) {
      this.e = var1;
   }

   String e() {
      return this.f;
   }

   void c(String var1) {
      this.f = var1;
   }

   String f() {
      return this.g;
   }

   void d(String var1) {
      this.g = var1;
   }

   public String getComment() {
      return this.h;
   }

   public void setComment(String value) {
      this.h = value;
   }

   byte g() {
      return this.i;
   }

   void a(byte var1) {
      this.i = var1;
   }

   WorksheetCollection h() {
      return this.l;
   }

   Name(WorksheetCollection sheets) {
      this.l = sheets;
      this.b = new zaoe();
   }

   Name(WorksheetCollection sheets, String text) {
      this.l = sheets;
      this.b = new zaoe();
      this.b.e = text;
   }

   static int e(String var0) {
      boolean var1 = true;
      byte var2;
      switch(m.a(var0.toUpperCase())) {
      case 0:
         var2 = 0;
         break;
      case 1:
         var2 = 1;
         break;
      case 2:
         var2 = 2;
         break;
      case 3:
         var2 = 3;
         break;
      case 4:
         var2 = 4;
         break;
      case 5:
         var2 = 5;
         break;
      case 6:
         var2 = 6;
         break;
      case 7:
         var2 = 7;
         break;
      case 8:
         var2 = 8;
         break;
      case 9:
         var2 = 9;
         break;
      case 10:
         var2 = 10;
         break;
      case 11:
         var2 = 11;
         break;
      case 12:
         var2 = 12;
         break;
      case 13:
         var2 = 13;
         break;
      default:
         return -1;
      }

      return var2;
   }

   void f(String var1) {
      if (var1.startsWith("_xlnm.")) {
         var1 = var1.substring(6);
      }

      int var2 = e(var1);
      if (var2 != -1) {
         this.j = (byte)var2;
         this.b.e = var1;
         this.b((int)0);
      }

   }

   public String getText() {
      return this.b.e;
   }

   public void setText(String value) {
      this.l.getNames().a(this, value);
      this.b.e = value;
   }

   public String getFullText() {
      if (this.getSheetIndex() != 0) {
         String var1 = this.l.get(this.k - 1).getName();
         if (zakq.b(var1)) {
            var1 = "'" + var1 + "'";
         }

         return var1 + "!" + this.b.e;
      } else {
         return this.b.e;
      }
   }

   String i() {
      return this.b.e;
   }

   void g(String var1) {
      this.b.e = var1;
   }

   public String getRefersTo() {
      if (this.c == null && this.b.f != null) {
         this.c = this.l.b().a(-1, -1, this.b.f, 0, 0, true);
      }

      return this.c;
   }

   public void setRefersTo(String value) {
      this.c = value;
      this.b.a = null;
      if (value != null && !"".equals(value)) {
         if (!value.startsWith("=")) {
            this.c = "=" + value;
         }

         this.b.f = this.l.x().a(-1, this.c, 0, 0, 2, 32, false, true, false);
      } else {
         this.b.f = null;
      }

   }

   void h(String var1) {
      this.c = var1;
      this.b.a = null;
   }

   void i(String var1) {
      this.c = var1;
      if (var1 != null && !"".equals(var1)) {
         this.b.f = this.l.x().a(-1, this.c, 0, 0, 2, 32, false, true, false);
         if (this.l.x().b()) {
            this.b.f = null;
         } else {
            this.c = null;
         }

      }
   }

   public String getR1C1RefersTo() {
      return this.l.c().a(-1, -1, this.b.f, 0, 0, true);
   }

   public void setR1C1RefersTo(String value) {
      String var2 = zasp.b(value, 0, 0);
      this.setRefersTo(var2);
      this.b.a = null;
   }

   public boolean isReferred() {
      int var1 = this.l.getNames().b(this.b.e, this.getSheetIndex() - 1);
      if (var1 == -1) {
         return false;
      } else {
         Cell var2 = null;

         for(int var3 = 0; var3 < this.l.getCount(); ++var3) {
            Cells var4 = this.l.get(var3).getCells();

            int var7;
            for(int var5 = 0; var5 < var4.getRows().getCount(); ++var5) {
               Row var6 = var4.getRows().getRowByIndex(var5);

               for(var7 = 0; var7 < var6.a(); ++var7) {
                  var2 = var6.getCellByIndex(var7);
                  if (var2.f()) {
                     if (var2.D() != null) {
                        if (zyo.a(var2.D().d(), -1, -1, var1, this.l)) {
                           return true;
                        }
                     } else if (zyo.a(var2.v(), -1, -1, var1, this.l)) {
                        return true;
                     }
                  }
               }
            }

            Worksheet var12 = this.l.get(var3);
            if (var12.t() != null && var12.getCharts().getCount() > 0 && var12.getCharts().a(var1)) {
               return true;
            }

            ConditionalFormattingCollection var13 = var12.getConditionalFormattings();

            for(var7 = 0; var7 < var13.getCount(); ++var7) {
               FormatConditionCollection var8 = var13.get(var7);

               for(int var9 = 0; var9 < var8.getCount(); ++var9) {
                  FormatCondition var10 = var8.get(var9);
                  var10.f();
                  byte[] var11;
                  if (var10.a() != null) {
                     var11 = var10.a();
                     if (zyo.a(var11, -1, var11.length - 1, var1, this.l)) {
                        return true;
                     }
                  }

                  if (var10.c() != null) {
                     var11 = var10.c();
                     if (zyo.a(var11, -1, var11.length - 1, var1, this.l)) {
                        return true;
                     }
                  }
               }
            }

            ValidationCollection var14 = var12.getValidations();

            for(int var15 = 0; var15 < var14.getCount(); ++var15) {
               Validation var16 = var14.get(var15);
               byte[] var17;
               if (var16.d() != null) {
                  var17 = (byte[])var16.d();
                  if (zyo.a(var17, 0, var17.length - 1, var1, this.l)) {
                     return true;
                  }
               }

               if (var16.e() != null) {
                  var17 = (byte[])var16.e();
                  if (zyo.a(var17, 0, var17.length - 1, var1, this.l)) {
                     return true;
                  }
               }
            }
         }

         return false;
      }
   }

   public boolean isVisible() {
      return !this.j();
   }

   public void setVisible(boolean value) {
      this.a(!value);
   }

   boolean j() {
      return (this.b.d & '\uffff' & 1) != 0;
   }

   void a(boolean var1) {
      if (var1) {
         this.b.d |= 1;
      } else {
         this.b.d &= 65534;
      }

   }

   boolean k() {
      return (this.b.d & '\uffff' & 4) != 0;
   }

   boolean l() {
      return (this.b.d & '\uffff' & 8) != 0;
   }

   void b(boolean var1) {
      if (var1) {
         this.b.d |= 8;
      } else {
         this.b.d &= 65407;
      }

   }

   void m() {
      this.c = null;
   }

   int n() {
      if ((this.b.d & '\uffff' & 32) != 0) {
         return 0;
      } else {
         return (this.b.d & '\uffff' & 4) != 0 ? 1 : 2;
      }
   }

   void b(int var1) {
      switch(var1) {
      case 0:
         this.b.d |= 32;
         break;
      case 1:
         this.b.d |= 4;
         break;
      case 2:
         this.b.d = this.b.d & '\uffff' & 'ￛ';
      }

   }

   public int getSheetIndex() {
      return this.k;
   }

   public void setSheetIndex(int value) {
      this.k = value;
   }

   int o() {
      int var1 = -1;
      int var2;
      int var3;
      if (this.h().n().k()) {
         if (this.b.f != null && this.b.f.length > 2) {
            switch(this.b.f[4]) {
            case 58:
            case 59:
            case 90:
            case 91:
            case 122:
            case 123:
               var2 = com.aspose.cells.b.a.zc.e(this.b.f, 5) & '\uffff';
               var3 = this.l.q().c(var2);
               if (var3 == this.l.u()) {
                  var1 = this.l.q().d(var2);
               }
            }
         }
      } else if (this.b.f != null && this.b.f.length > 2) {
         switch(this.b.f[2]) {
         case 58:
         case 59:
         case 90:
         case 91:
         case 122:
         case 123:
            var2 = com.aspose.cells.b.a.zc.e(this.b.f, 3) & '\uffff';
            var3 = this.l.q().c(var2);
            if (var3 == this.l.u()) {
               var1 = this.l.q().d(var2);
            }
         }
      }

      return var1;
   }

   byte p() {
      return this.j;
   }

   void a(int var1, CellArea var2) {
      this.b.f = zaav.a(this.l, var1, var2);
      this.c = null;
      this.b.a = null;
   }

   static String b(byte var0) {
      String var1 = null;
      switch(var0) {
      case 0:
         var1 = "CONSOLIDATE_AREA";
         break;
      case 1:
         var1 = "AUTO_OPEN";
         break;
      case 2:
         var1 = "AUTO_CLOSE";
         break;
      case 3:
         var1 = "EXTRACT";
         break;
      case 4:
         var1 = "DATABASE";
         break;
      case 5:
         var1 = "CRITERIA";
         break;
      case 6:
         var1 = "PRINT_AREA";
         break;
      case 7:
         var1 = "PRINT_TITLES";
         break;
      case 8:
         var1 = "RECORDER";
         break;
      case 9:
         var1 = "DATA_FORM";
         break;
      case 10:
         var1 = "AUTO_ACTIVATE";
         break;
      case 11:
         var1 = "AUTO_DEACTIVATE";
         break;
      case 12:
         var1 = "SHEET_TITLE";
         break;
      case 13:
         var1 = "_FILTERDATABASE";
      }

      return var1;
   }

   void b(byte[] var1) {
      this.b.d = com.aspose.cells.b.a.zc.e(var1, 0);
      this.i = var1[2];
      this.k = com.aspose.cells.b.a.zc.e(var1, 8) & '\uffff';
      byte var2 = 14;
      byte var3 = var1[3];
      int var7;
      if (this.n() == 0) {
         this.j = var1[15];
         var7 = 16;
         this.b.e = b(var1[15]);
      } else {
         byte var4 = var1[14];
         if (var4 != 0) {
            this.b.e = Encoding.getUnicode().a(var1, 15, (var3 & 255) * 2);
            var7 = var2 + 2 * (var3 & 255) + 1;
         } else {
            byte[] var5 = new byte[2 * (var3 & 255)];

            for(int var6 = 0; var6 < 2 * (var3 & 255); ++var6) {
               if (var6 % 2 == 0) {
                  var5[var6] = var1[15 + var6 / 2];
               }
            }

            this.b.e = Encoding.getUnicode().a(var5);
            var7 = var2 + (var3 & 255) + 1;
         }

         if (this.b.e != null && this.b.e.indexOf(32) != -1) {
            this.b.e = com.aspose.cells.b.a.zv.a(this.b.e, " ", "");
         }

         if (this.b.e != null) {
            String var9 = this.b.e.toUpperCase();
            switch(m.a(var9)) {
            case 0:
               this.j = 0;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 1:
               this.j = 1;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 2:
               this.j = 2;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 3:
               this.j = 3;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 4:
               this.j = 4;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 5:
               this.j = 5;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 6:
               this.j = 6;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 7:
               this.j = 7;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 8:
               this.j = 8;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 9:
               this.j = 9;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 10:
               this.j = 10;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 11:
               this.j = 11;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 12:
               this.j = 12;
               this.b.e = var9;
               this.b((int)0);
               break;
            case 13:
               this.j = 13;
               this.b.e = var9;
               this.b((int)0);
            }
         }
      }

      int var8 = com.aspose.cells.b.a.zc.e(var1, 4) & '\uffff';
      int var10 = (var1[10] & 255) + (var1[11] & 255) + (var1[12] & 255) + (var1[13] & 255);
      if (var10 == 0) {
         if (var8 != 0) {
            this.b.f = new byte[var1.length - var7 + 2];
            System.arraycopy(var1, 4, this.b.f, 0, 2);
            System.arraycopy(var1, var7, this.b.f, 2, this.b.f.length - 2);
         }
      } else {
         if (var8 != 0) {
            this.b.f = new byte[var8 + 2];
            System.arraycopy(var1, 4, this.b.f, 0, 2);
            System.arraycopy(var1, var7, this.b.f, 2, this.b.f.length - 2);
            var7 += this.b.f.length - 2;
         }

         if (var1[10] != 0) {
            if (var1[var7] == 0) {
               this.d = Encoding.getASCII().a(var1, var7 + 1, var1[10] & 255);
               var7 += 1 + (var1[10] & 255);
            } else {
               this.d = Encoding.getUnicode().a(var1, var7 + 1, (var1[10] & 255) * 2);
               var7 += 1 + (var1[10] & 255) * 2;
            }
         }

         if (var1[11] != 0) {
            if (var1[var7] == 0) {
               this.e = Encoding.getASCII().a(var1, var7 + 1, var1[11] & 255);
               var7 += 1 + (var1[11] & 255);
            } else {
               this.e = Encoding.getUnicode().a(var1, var7 + 1, (var1[11] & 255) * 2);
               var7 += 1 + (var1[11] & 255) * 2;
            }
         }

         if (var1[12] != 0) {
            if (var1[var7] == 0) {
               this.f = Encoding.getASCII().a(var1, var7 + 1, var1[12] & 255);
               var7 += 1 + (var1[12] & 255);
            } else {
               this.f = Encoding.getUnicode().a(var1, var7 + 1, (var1[12] & 255) * 2);
               var7 += 1 + (var1[12] & 255) * 2;
            }
         }

         if (var1[13] != 0) {
            int var10000;
            if (var1[var7] == 0) {
               this.g = Encoding.getASCII().a(var1, var7 + 1, var1[13] & 255);
               var10000 = var7 + 1 + (var1[13] & 255);
            } else {
               this.g = Encoding.getUnicode().a(var1, var7 + 1, (var1[13] & 255) * 2);
               var10000 = var7 + 1 + (var1[13] & 255) * 2;
            }
         }
      }

   }

   byte[] q() {
      if (this.b.f == null) {
         return null;
      } else {
         byte[] var1;
         if (this.h().n().k()) {
            var1 = new byte[this.b.f.length - 8];
            System.arraycopy(this.b.f, 4, var1, 0, var1.length);
            return var1;
         } else {
            var1 = new byte[this.b.f.length - 2];
            System.arraycopy(this.b.f, 2, var1, 0, var1.length);
            return var1;
         }
      }
   }

   void a(Name var1) {
      this.j = var1.j;
      this.k = var1.k;
      this.b.d = var1.b.d;
      this.b.e = var1.b.e;
      this.b.f = zyd.a(var1.l, this.l, var1.b.f, -1, 0, 0);
      this.h = var1.h;
      this.d = var1.d;
      this.e = var1.e;
      this.f = var1.f;
      this.i = var1.i;
      this.c = var1.c;
      this.g = var1.g;
   }

   void b(Name var1) {
      this.b.d = var1.b.d;
      this.j = var1.j;
      this.h = var1.h;
      this.d = var1.d;
      this.e = var1.e;
      this.f = var1.f;
      this.i = var1.i;
      this.g = var1.g;
      if (var1.b.f != null && var1.b.f.length > 2) {
         this.b.f = zyd.a(var1.l, this.l, var1.b.f, -1, 0, 0);
      } else {
         this.c = var1.c;
      }

   }

   void a(Name var1, HashMap var2, int var3) {
      this.b.d = var1.b.d;
      this.j = var1.j;
      this.h = var1.h;
      this.d = var1.d;
      this.e = var1.e;
      this.f = var1.f;
      this.i = var1.i;
      this.c = var1.c;
      this.g = var1.g;
      if (var1.b.f != null && var1.b.f.length > 2) {
         this.b.f = zyd.a(var1.l, this.l, var1.b.f, -1, 0, 0);
         zyo.a(this.h(), var2, false, var3, -1, -1, this.b.f);
      }

   }

   void r() {
      --this.k;
   }

   public String toString() {
      return com.aspose.cells.b.a.zv.a("Aspose.Cells.Name [ {0}; ReferTo:{1}]", this.getText(), this.getRefersTo());
   }

   int[] a(int var1, int var2, boolean var3) {
      int[] var4 = zaav.a(this.l, this.b.f, -1, true, var1, var2);
      if (var4 == null && this.b.f != null && var3) {
         zabd var5 = this.l.x().a((Name)this, (Cell)null);
         boolean var6 = false;
         if (var5 != null) {
            if (var5.b() != null) {
               switch(m.a(var5.b())) {
               case 14:
               case 15:
               case 16:
                  var6 = true;
               }
            } else if (var5.f()[0] == 35) {
               var6 = true;
            }

            if (var6) {
               zyh var7 = new zyh(this.l.n());
               var7.a(2);
               Object var8 = var7.b(var5, (Cell)null);
               if (var8 != null && var8 instanceof zft) {
                  zft var9 = (zft)var8;
                  var4 = new int[]{this.l.q().b(var9.a, var9.b), var9.d.StartRow, var9.d.StartColumn, var9.d.EndRow, var9.d.EndColumn};
               }
            }
         }
      }

      return var4;
   }

   Range c(boolean var1) {
      if (this.b.a()) {
         return null;
      } else {
         CalculationOptions var2 = new CalculationOptions();
         var2.b = true;
         var2.h = false;
         zaay var3 = new zaay(this.l.get(this.k > 1 ? this.k - 1 : 0), 3, var2);
         var3.a = 1;
         var3.f = this;
         zagu var4 = null;

         try {
            var4 = (new zyg(var3, this.b.f, 0, -1)).a();
         } catch (Exception var6) {
            return null;
         }

         var4 = zaaq.b(var4, var3);
         if (var4.b() != 9) {
            return null;
         } else {
            Range var5 = this.a(((zaal)var4).k());
            if (var5 == null) {
               return null;
            } else {
               if (this.k != 0) {
                  var5.a(this.l.get(this.k - 1).getName() + "!" + this.b.e);
               } else {
                  var5.a(this.b.e);
               }

               return var5;
            }
         }
      }
   }

   Range s() {
      return this.c(true);
   }

   void a(int var1, int var2, int var3) {
      zyo.a(this.l.get(var1), false, var2, var3, var2, var2, -1, -1, this.b.f);
      this.c = null;
      this.b.a = null;
   }

   void b(int var1, int var2, int var3) {
      zyo.c(this.l.get(var1), false, var2, var3, var2, var2, -1, -1, this.b.f);
      this.c = null;
      this.b.a = null;
   }

   public Range[] getRanges() {
      ArrayList var1 = zyo.a(this.b.f, -1, -1, (WorksheetCollection)this.l, (Cells)null);
      if (var1 != null && var1.size() != 0) {
         Range[] var2 = new Range[var1.size()];

         for(int var3 = 0; var3 < var1.size(); ++var3) {
            var2[var3] = (Range)var1.get(var3);
         }

         return var2;
      } else {
         return null;
      }
   }

   Range[] t() {
      if (this.b.a()) {
         return null;
      } else {
         CalculationOptions var1 = new CalculationOptions();
         var1.b = true;
         var1.h = false;
         zaay var2 = new zaay(this.l.get(this.k > 1 ? this.k - 1 : 0), 3, var1);
         var2.a = 1;
         var2.f = this;
         zagu var3 = null;

         try {
            var3 = (new zyg(var2, this.b.f, 0, -1)).a();
         } catch (Exception var9) {
            return null;
         }

         var3 = zaaq.b(var3, var2);
         if (var3.b() == 9) {
            Range var10 = this.a(((zaal)var3).k());
            return var10 == null ? null : new Range[]{var10};
         } else if (var3.b() == 5 && ((zzl)var3).a() == 16) {
            zagu[] var4 = zaaq.a((zzw)var3);
            Range[] var5 = new Range[var4.length];
            int var6 = 0;

            for(int var7 = 0; var7 < var4.length; ++var7) {
               var3 = zaaq.b(var4[var7], var2);
               if (var3.b() == 9) {
                  Range var8 = this.a(((zaal)var3).k());
                  if (var8 != null) {
                     var5[var6] = var8;
                     ++var6;
                  }
               }
            }

            if (var6 < var5.length) {
               Range[] var11 = new Range[var6];
               System.arraycopy(var5, 0, var11, 0, var6);
               return var11;
            } else {
               return var5;
            }
         } else {
            return null;
         }
      }
   }

   private Range a(zaye var1) {
      if (var1.a() != null && (var1.a().a & '\uffff') == this.l.u()) {
         int var2 = var1.a().b & '\uffff';
         if (var2 == (var1.a().c & '\uffff') && var2 >= 0 && var2 < this.l.getCount()) {
            Cells var3 = this.l.get(var2).getCells();
            return var3.createRange(var1.b(), var1.d(), var1.q(), var1.p());
         } else {
            return null;
         }
      } else {
         return null;
      }
   }

   public Range getRange() {
      Range var1 = this.s();
      return var1;
   }

   public Range getRange(int sheetIndex, int row, int column) {
      if (this.b.a()) {
         return null;
      } else {
         CalculationOptions var4 = new CalculationOptions();
         var4.b = true;
         var4.h = false;
         zaay var5 = new zaay(this.l.get(sheetIndex), 3, var4);
         var5.a = 1;
         var5.f = this;
         var5.g = row;
         var5.h = (short)column;
         zagu var6 = null;

         try {
            var6 = (new zyg(var5, this.b.f, 0, -1)).a();
         } catch (Exception var8) {
            return null;
         }

         var6 = zaaq.b(var6, var5);
         if (var6.b() != 9) {
            return null;
         } else {
            Range var7 = ((zaal)var6).k().b(var5);
            if (var7 != null) {
               if (this.k != 0) {
                  var7.a(this.l.get(this.k - 1).getName() + "!" + this.b.e);
               } else {
                  var7.a(this.b.e);
               }
            }

            return var7;
         }
      }
   }

   Range d(boolean var1) {
      return this.c(var1);
   }

   void u() {
      this.b.f = null;
      this.c = null;
   }
}
